package ru.chaykin;

import java.io.IOException;

import com.codeminders.hidapi.ClassPathLibraryLoader;
import com.codeminders.hidapi.HIDDevice;
import com.codeminders.hidapi.HIDDeviceNotFoundException;
import com.codeminders.hidapi.HIDManager;

@Deprecated
public class HID {
	private static volatile HID hid;

	public static final int VID  = 0x0483;
	public static final int PID = 0x5750;

	private HID() {
		if (!ClassPathLibraryLoader.loadNativeHIDLibrary())
			throw new RuntimeException();
	};

	private static void instance() {
		if (hid == null) {
			synchronized (HID.class) {
				if (hid == null)
					hid = new HID();
			}
		}
	}

	public static HIDDevice getHIDDevice(int pid, int vid) throws HIDDeviceNotFoundException, IOException {
		instance();
		return HIDManager.getInstance().openById(vid, pid, null);
	}

	public static HIDDevice getHIDDevice() throws HIDDeviceNotFoundException, IOException {
		return getHIDDevice(PID, VID);
	}
}
